package impl

import (
	"context"
	"git.mycaigou.com/gfyx/micro-gfyx-bigdata-service/infrastructure/repository/bigdata/contract"
	"git.mycaigou.com/gfyx/micro-gfyx-bigdata-service/infrastructure/repository/model/bigdata"
	"git.myscrm.cn/golang/stark/v4"
	"gorm.io/gorm"
)

type ApiRepo struct {
}

func NewApiRepo() contract.ApiRepoIface {
	return &ApiRepo{}
}

func (a *ApiRepo) GetApiInfo(ctx context.Context, path string) (*bigdata.Api, error) {
	db := stark.MySQLConn.Get(ctx)
	api := bigdata.Api{}
	db = db.Where("request_path = ? and is_deleted = 0", path).First(&api)
	if db.Error != nil && db.Error != gorm.ErrRecordNotFound {
		return nil, db.Error
	}
	return &api, nil
}
